import java.util.Arrays;

/**
 * 子数组
 */
public class Demo01 {

  public static void main(String[] args) {
    int[] srcArr = {11, 22, 33, 44, 55, 66};
    int[] targetArr;//{22,33,44}
    System.out.println(Arrays.toString(srcArr));
    targetArr = sub(srcArr,1,4);
    System.out.println(Arrays.toString(targetArr));

  }

  /**
   * 截取源数组中从startIndex到endIndex的子数组
   * @param srcArr 源数组
   * @param startIndex 开始的索引(含)
   * @param endIndex 结束的索引(不含)
   * @return 数组
   */
  public static int[] sub(int[] srcArr, int startIndex, int endIndex) {
    int[] arr = new int[endIndex-startIndex];
//    for(int i = startIndex;i<endIndex;i++){
//      arr[i-startIndex] = srcArr[i];
//    }
    System.arraycopy(srcArr,startIndex,arr,0,endIndex-startIndex);
    return arr;
  }
}
